// 获取DOM元素
const actionButton = document.getElementById('actionButton');
const statusDiv = document.getElementById('status');

// 初始化状态
let isActive = false;

// 从存储中获取状态
chrome.storage.local.get(['isActive'], function(result) {
  isActive = result.isActive || false;
  updateUI();
});

// 按钮点击事件处理
actionButton.addEventListener('click', function() {
  isActive = !isActive;
  
  // 保存状态到存储
  chrome.storage.local.set({ isActive: isActive }, function() {
    updateUI();
    
    // 向background script发送消息
    chrome.runtime.sendMessage({ 
      action: 'toggle', 
      isActive: isActive 
    });
  });
});

// 更新UI显示
function updateUI() {
  if (isActive) {
    actionButton.textContent = 'Stop';
    actionButton.style.backgroundColor = '#f44336';
    statusDiv.textContent = 'Extension is active';
  } else {
    actionButton.textContent = 'Start';
    actionButton.style.backgroundColor = '#4CAF50';
    statusDiv.textContent = 'Extension is inactive';
  }
} 